﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestSound : MonoBehaviour {


    public static AndroidJavaClass unityActivityClass;
    public static AndroidJavaObject activityObj;
    private static AndroidJavaObject soundObj;

    public string[] AllSound;
    public int[] allSoundIdx;
    public void  LoadAll()
    {
        unityActivityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

        activityObj = unityActivityClass.GetStatic<AndroidJavaObject>("currentActivity");

        soundObj = new AndroidJavaObject("com.plugins.unity.vibrator.AudioCenter", 5, activityObj);
        allSoundIdx = new int[AllSound.Length];
        for (int i = 0; i < AllSound.Length; i++)
        {
            Debug.Log(AllSound[i]);
            allSoundIdx[i] = loadSound(AllSound[i]+".ogg");
            Debug.Log(allSoundIdx[i]);
        }

    }
    public static void playSound(int soundId, float volume)
    {
        soundObj.Call("playSound", new object[] { soundId, volume });
    }

    public static int loadSound(string soundName)
    {
        return soundObj.Call<int>("loadSound", new object[] { soundName });
    }

    public static void unloadSound(int soundId)
    {
        soundObj.Call("unloadSound", new object[] { soundId });
    }


    public  void  Play(int idx)
    {
        playSound(allSoundIdx[idx], 1);
    }

    public void Unload(int idx)
    {
        unloadSound(allSoundIdx[idx]);
    }
}
